﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class CardModel : Game {


    #region card Defines
    public List<GameObject> CardListObj;
    public static int FourTeenCard;
    EginMahjong mahjong = EginMahjong.Instance;

    private int DownCardCount=0;
    private int RightCardCount = 0;
    private int UpCardCount = 0;
    private int LeftCardCount =0 ;
    public List<GameObject> DownCardShowObj;
    public List<GameObject> RightCardShowObj;
    public List<GameObject> UpCardShowObj;
    public List<GameObject> LeftCardShowObj;

    public GameObject Sign;

    //听牌
    public GameObject tingCard;
    public List<UISprite> tingCardList;
    public List<GameObject> tingBgList;
    //托管
    public GameObject AutoOutCard;
    public GameObject CancelBtn;

    private string DownSpecialChiOrPeng = "GameMahjong/NextGameP/SpecialCard/DownSpecialChiOrPeng";
    private string DownSpecialCard = "GameMahjong/NextGameP/SpecialCard/DownSpecialCard";
    private string RightSpecialCard = "GameMahjong/NextGameP/SpecialCard/RightSpecialCard";
    private string UpSpecialCard = "GameMahjong/NextGameP/SpecialCard/UpSpecialCard";
    private string LeftSpecialCard = "GameMahjong/NextGameP/SpecialCard/LeftSpecialCard";

    private string DownSpecialCardDarkGang = "GameMahjong/NextGameP/SpecialCard/DownSpecialCardDarkGang";
    private string LeftSpecialCardDarkGang = "GameMahjong/NextGameP/SpecialCard/LeftSpecialCardDarkGang";
    private string RightSpecialCardDarkGang = "GameMahjong/NextGameP/SpecialCard/RightSpecialCardDarkGang";
    private string UpSpecialCardDarkGang = "GameMahjong/NextGameP/SpecialCard/UpSpecialCardDarkGang";

    public Transform DownSpecialCardFather;
    public Transform RightSpecialCardFather;
    public Transform UpSpecialCardFather;
    public Transform LeftSpecialCardFather;
    private float DownSpecialX=-765;
    
    private float RightSpecialX = 491;
    private float RightSpecialY = 270;
    private float UpSpecialX = -429;
    private float LeftSpecialX = -693;
    private float LeftSpecialY = -177;
    

    public List<GameObject> RightBaiCard;
    public List<GameObject> UpBaiCard;
    public List<GameObject> LeftBaiCard;

    public UISprite DirectionBg;
    public List<UISprite> DirectionList;

    private const float iTweenmoveSpeed=1.0f;

    private Dictionary<int, GameObject> DownSpecialDic = new Dictionary<int, GameObject>();
    private Dictionary<int, GameObject> LeftSpecialDic = new Dictionary<int, GameObject>();
    private Dictionary<int, GameObject> RightSpecialDic = new Dictionary<int, GameObject>();
    private Dictionary<int, GameObject> UpSpecialDic = new Dictionary<int, GameObject>();
    //剩余牌
    public GameObject remainCountObj;
    public UILabel remainCount;

    //倒计时
    public UILabel Countdown;
    #endregion

    #region sound Defines
    public List<AudioClip> audioClipListMan;
    public List<AudioClip> audioClipListWomen;
    #endregion sound Defines

    #region Effect Defines
    public Transform EffectFather;
    public Transform SignTransform;
    private string PengPath = "GameMahjong/NextGameP/Effect/Peng";
    private string GangPath = "GameMahjong/NextGameP/Effect/Gang";
    private string HuPath = "GameMahjong/NextGameP/Effect/Hu";
    #endregion

    void Awake()
    {
        UIEventListener.Get(CancelBtn).onClick = ButtonClick;
        //LoadTest();
    }

    void ButtonClick(GameObject button)
    {
        
        if (button.name == "CancelBtn")
        {
            UserCancelRobotRequest MR = new Pb.UserCancelRobotRequest { };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(MR, MsgId.UserCancelRobotRequest);
            AutoOutCard.SetActive(false);
        }
    }
    private void Start()
    {
        remainCount.text = mahjong.remainCount.ToString();
        CardLoad();
    }

    public float CountdownCount = 13f;
    private void Update()
    {
        CountdownCount -= Time.deltaTime;
        if (mahjong.roomStatus == ROOM_STATUS.Gaming) {
            if (CountdownCount > 0)
            {
                int i = (int)CountdownCount;
                Countdown.text = i.ToString();
            }
            else if (CountdownCount < 0)
            {
                CountdownCount = 13f;
            }
        }
       
    }
    #region 重连

    void CardLoad() {

        
        #region 加载牌
        if (mahjong.roomStatus == ROOM_STATUS.Gaming)
        {
            if (mahjong.handCard != 0)
            {
                FourTeenCard = mahjong.handCard;
                CardListObj[13].SetActive(true);
                CardListObj[13].GetComponent<UISprite>().spriteName = FourTeenCard.ToString();
                CardListObj[13].GetComponent<UIButton>().normalSprite = FourTeenCard.ToString();
                CardListObj[13].name = FourTeenCard.ToString();
                SortCard();
            }
            else
            {
                CardListObj[13].SetActive(false);
                SortCard();
            }
        }


        #endregion

        //加载direction
        LoadIndex();
        //重连
        if (mahjong.roomStatus == ROOM_STATUS.Gaming && mahjong.gameRecent)
        {
            Reconnet();
            mahjong.gameRecent = false;
        }
        LoadDirection(returnOtherSeatIndex(mahjong.bankerSid));
        DirectionList[returnOtherSeatIndex(mahjong.nextSid) - 1].gameObject.SetActive(true);

    }

    void Reconnet() {
        /*
         user.OtherOutCardList = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.OutCardList.ToList());
         user.mahjongDoneSpecialCard =newpb.SpecialDoneList.ToList();
         */
        
        #region tableoutcard
        for (int i = 1; i <= mahjong.OtherOutCardList.Count; i++)
        {
            for (int j = 0; j < mahjong.OtherOutCardList[i].Count; j++)
            {
                if (returnOtherSeatIndex(i)==1)
                {
                    DownCardShowObj[DownCardCount].SetActive(true);
                    DownCardShowObj[DownCardCount].GetComponent<UISprite>().spriteName = mahjong.OtherOutCardList[i][j].ToString();
                    DownCardCount++;
                }
                else if (returnOtherSeatIndex(i) == 2) {
                    RightCardShowObj[RightCardCount].SetActive(true);
                    RightCardShowObj[RightCardCount].GetComponent<UISprite>().spriteName = mahjong.OtherOutCardList[i][j].ToString();
                    RightCardCount++;
                }
                else if (returnOtherSeatIndex(i) == 3)
                {
                    UpCardShowObj[UpCardCount].SetActive(true);
                    UpCardShowObj[UpCardCount].GetComponent<UISprite>().spriteName = mahjong.OtherOutCardList[i][j].ToString();
                    UpCardCount++;
                }
                else if (returnOtherSeatIndex(i) == 4)
                {
                    LeftCardShowObj[LeftCardCount].SetActive(true);
                    LeftCardShowObj[LeftCardCount].GetComponent<UISprite>().spriteName = mahjong.OtherOutCardList[i][j].ToString();
                    LeftCardCount++;
                }                
            }
        }
        #endregion tableoutcard

        #region  special card

        for (int i=0;i< mahjong.mahjongDoneSpecialCard.Count;i++) {
            
            for (int j = 0; j < mahjong.mahjongDoneSpecialCard[i].SpecialList.Count; j++) {
                int targetCard = mahjong.mahjongDoneSpecialCard[i].SpecialList[j].TargetCard;
                List<int> tempList = new List<int>();
                
                if (returnOtherSeatIndex(i + 1) == 1)
                {
                    if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.Peng) {
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(DownSpecialCard, DownSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);
                        DownSpecialX = DownSpecialX + 150;

                        DownSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.AddGang
                        || mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.LightGang)
                    {
                        //显示杠牌摆到一边
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(DownSpecialCard, DownSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);
                        DownSpecialX = DownSpecialX + 200;

                        DownSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.DarkGang ) {
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(DownSpecialCardDarkGang, DownSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);
                        DownSpecialX = DownSpecialX + 150;

                        DownSpecialDic.Add(targetCard, go);
                    }
                }
                else if (returnOtherSeatIndex(i + 1) == 2)
                {

                    if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.Peng)
                    {
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        GameObject go = LoadModelReturnObj(RightSpecialCard, RightSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
                        RightSpecialY = RightSpecialY - 125;

                        RightSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.AddGang
                        || mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.LightGang)
                    {
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(RightSpecialCard, RightSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
                        RightSpecialY = RightSpecialY - 161;

                        RightSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.DarkGang)
                    {
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
                        RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(RightSpecialCardDarkGang, RightSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
                        RightSpecialY = RightSpecialY - 125;

                        RightSpecialDic.Add(targetCard, go);
                    }
                }
                else if (returnOtherSeatIndex(i + 1) == 3)
                {
                    
                    if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.Peng)
                    {
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        GameObject go = LoadModelReturnObj(UpSpecialCard, UpSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(UpSpecialX, 297, 0);
                        UpSpecialX = UpSpecialX + 140;
                        
                        UpSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.AddGang  
                        || mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.LightGang)
                    {
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(UpSpecialCard, UpSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(UpSpecialX, 297, 0);
                        UpSpecialX = UpSpecialX + 190;
                        
                        UpSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.DarkGang)
                    {
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
                        UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(UpSpecialCardDarkGang, UpSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(UpSpecialX, 297, 0);
                        UpSpecialX = UpSpecialX + 140;

                        UpSpecialDic.Add(targetCard, go);
                    }
                }
                else if (returnOtherSeatIndex(i + 1) == 4)
                {
                    
                    if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.Peng)
                    {
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        GameObject go = LoadModelReturnObj(LeftSpecialCard, LeftSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(LeftSpecialX, LeftSpecialY, 0);
                        LeftSpecialY = LeftSpecialY + 130;
                        
                        LeftSpecialDic.Add(targetCard, go);
                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.AddGang  
                        || mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.LightGang)
                    {
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(LeftSpecialCard, LeftSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(LeftSpecialX, LeftSpecialY, 0);
                        LeftSpecialY = LeftSpecialY + 160;
                        
                        LeftSpecialDic.Add(targetCard, go);

                    }
                    else if (mahjong.mahjongDoneSpecialCard[i].SpecialList[j].ActionType == MAHJONG_ACTION_TYPE.DarkGang)
                    {
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
                        LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(0);
                        tempList.Add(targetCard);
                        GameObject go = LoadModelReturnObj(LeftSpecialCardDarkGang, LeftSpecialCardFather);
                        go.GetComponent<ShowSpecialCard>().Load(tempList);
                        go.transform.localPosition = new Vector3(LeftSpecialX, LeftSpecialY, 0);
                        LeftSpecialY = LeftSpecialY + 130;

                        LeftSpecialDic.Add(targetCard, go);
                    }
                }
            }
        }
        #endregion

        #region  sign
        if (mahjong.tableCard != 0)
        {
            Sign.SetActive(true);
            //加载出牌sign
            int tempWhoPut = (mahjong.turnSid - 1 == 0) ? 4 : mahjong.turnSid - 1;
            
            int WhoPut = returnOtherSeatIndex(tempWhoPut);
            if (WhoPut == 1)
            {
                
                Sign.transform.parent = SignTransform;
                Sign.transform.localPosition = new Vector3(DownCardShowObj[DownCardCount - 1].transform.localPosition.x, DownCardShowObj[DownCardCount - 1].transform.localPosition.y + 20, 0);
                
            }
            else if (WhoPut == 2)
            {

                
                Sign.transform.parent = SignTransform;
                Sign.transform.localPosition = new Vector3(RightCardShowObj[RightCardCount-1].transform.localPosition.x, RightCardShowObj[RightCardCount-1].transform.localPosition.y + 20, 0);
                

            }
            else if (WhoPut == 3)
            {
                

                Sign.transform.parent = SignTransform;
                Sign.transform.localPosition = new Vector3(UpCardShowObj[UpCardCount - 1].transform.localPosition.x, UpCardShowObj[UpCardCount - 1].transform.localPosition.y + 18, 0);
                
            }
            else if (WhoPut == 4)
            {
                
                Sign.transform.parent = SignTransform;
                Sign.transform.localPosition = new Vector3(LeftCardShowObj[LeftCardCount-1].transform.localPosition.x, LeftCardShowObj[LeftCardCount-1].transform.localPosition.y +25, 0);
               
            }
        }
        #endregion

        mahjong.OtherOutCardList.Clear();
        mahjong.mahjongDoneSpecialCard.Clear();
    }
    #endregion
   
    #region 加载direction
    void LoadDirection(int bankerSid) {
        if (bankerSid == 1) {
            DirectionBg.spriteName = "1";
            DirectionList[0].spriteName = "down1";
            DirectionList[1].spriteName = "right2";
            DirectionList[2].spriteName = "up3";
            DirectionList[3].spriteName = "left4";
        }
        else if (bankerSid == 2)
        {
            DirectionBg.spriteName = "2";
            DirectionList[0].spriteName = "down4";
            DirectionList[1].spriteName = "right1";
            DirectionList[2].spriteName = "up2";
            DirectionList[3].spriteName = "left3";
        }
        else if (bankerSid == 3)
        {
            DirectionBg.spriteName = "3";
            DirectionList[0].spriteName = "down3";
            DirectionList[1].spriteName = "right4";
            DirectionList[2].spriteName = "up1";
            DirectionList[3].spriteName = "left2";
        }
        else if (bankerSid == 4)
        {
            DirectionBg.spriteName = "4";
            DirectionList[0].spriteName = "down2";
            DirectionList[1].spriteName = "right3";
            DirectionList[2].spriteName = "up4";
            DirectionList[3].spriteName = "left1";
        }
    }
    #endregion

    #region  出牌处理
    //处理自己的出牌消息
    public void OwnOutCard(int outCard,int inCard) {


        CardListObj[13].SetActive(false);
        if (outCard == inCard)
        {
        }
        else {
            for (int i = 0; i < mahjong.CardList.Count; i++)
            {
                if (mahjong.CardList[i] == outCard)
                {
                    mahjong.CardList.RemoveAt(i);
                    break;
                }
            }
            if (inCard != 0)
            {
                mahjong.CardList.Add(inCard);
            }
            else
            {
                CardListObj[mahjong.CardList.Count].SetActive(false);
            }
            SortCard();
        }
        
        DownCardShowObj[DownCardCount].SetActive ( true);
        DownCardShowObj[DownCardCount].GetComponent<UISprite>().spriteName = outCard.ToString();
        //iTweenMove(DownCardShowObj[DownCardCount], DownCardShowObj[DownCardCount], CardListObj[13].transform);

        //播放 音效 outCard
        PlaySound(outCard);
        Sign.transform.parent = SignTransform;
        Sign.transform.localPosition = new Vector3(DownCardShowObj[DownCardCount].transform.localPosition.x, DownCardShowObj[DownCardCount].transform.localPosition.y + 20, 0);
        DownCardCount++;
        //整理牌
        for (int i = 0; i < CardListObj.Count; i++)
        {
            CardListObj[i].transform.localPosition = new Vector3(CardListObj[i].transform.localPosition.x, -307.8f, 0);
            CardListObj[i].GetComponent<CardButton>().TempBool = false;
        }
    }
    //处理出牌消息
    public void OtherOutCard(int outCard, int inCard,int WhoPut)
    {
        Sign.SetActive(true);
        if (WhoPut == 1)
        {
            
            DownCardShowObj[DownCardCount].SetActive(true);
            DownCardShowObj[DownCardCount].GetComponent<UISprite>().spriteName = outCard.ToString();

            Sign.transform.parent = DownCardShowObj[DownCardCount].transform;
            Sign.transform.localPosition = Vector3.zero;
            DownCardCount++;
            
        }
        else if (WhoPut == 2) {
            
            RightCardShowObj[RightCardCount].SetActive(true);
            RightCardShowObj[RightCardCount].GetComponent<UISprite>().spriteName = outCard.ToString();
            iTweenMove(RightCardShowObj[RightCardCount], RightCardShowObj[RightCardCount], RightBaiCard[RightBaiCard.Count-1].transform);
            //播放 音效 outCard
            PlaySound(outCard);
            Sign.transform.parent = SignTransform;
            Sign.transform.localPosition = new Vector3(RightCardShowObj[RightCardCount].transform.localPosition.x, RightCardShowObj[RightCardCount ].transform.localPosition.y + 20, 0);
            RightCardCount++;
            
        }
        else if (WhoPut == 3)
        {
            UpCardShowObj[UpCardCount].SetActive(true);
            UpCardShowObj[UpCardCount].GetComponent<UISprite>().spriteName = outCard.ToString();
            iTweenMove(UpCardShowObj[UpCardCount], UpCardShowObj[UpCardCount], UpBaiCard[0].transform);
            //播放 音效 outCard
            PlaySound(outCard);
            Sign.transform.parent = SignTransform;
            Sign.transform.localPosition = new Vector3(UpCardShowObj[UpCardCount].transform.localPosition.x, UpCardShowObj[UpCardCount].transform.localPosition.y + 18, 0);
            UpCardCount++;
            
        }
        else if (WhoPut == 4)
        {
            LeftCardShowObj[LeftCardCount].SetActive(true);
            LeftCardShowObj[LeftCardCount].GetComponent<UISprite>().spriteName = outCard.ToString();
            iTweenMove(LeftCardShowObj[LeftCardCount], LeftCardShowObj[LeftCardCount], LeftBaiCard[0].transform);
            //播放 音效 outCard
            PlaySound(outCard);
            Sign.transform.parent = SignTransform;
            Sign.transform.localPosition = new Vector3(LeftCardShowObj[LeftCardCount].transform.localPosition.x, LeftCardShowObj[LeftCardCount].transform.localPosition.y + 25, 0);
            LeftCardCount++;
            
        }
    }

    
    //处理到手的card 摸排
    public void MoCard() {
        
        FourTeenCard = mahjong.handCard;
        CardListObj[13].SetActive(true);
        CardListObj[13].GetComponent<UISprite>().spriteName = FourTeenCard.ToString();
        CardListObj[13].GetComponent<UIButton>().normalSprite = FourTeenCard.ToString();
        CardListObj[13].name = FourTeenCard.ToString();
        mahjong.handCard = 0;
    }

    #endregion

    #region 吃碰牌处理
    //处理自己吃牌
    public void OwnChiCard(int inCard,int siblingCard1,int siblingCard2)
    {
        LoadEffect(PengPath,1);
        //音效
        PlaySound(38);
        int tempCount=0;
        for (int i = 0; i < mahjong.CardList.Count; i++)
        {
            if (inCard == mahjong.CardList[i]) {
                tempCount++;
            }
        }

        if (tempCount == 4)
        {
            RemoveCardList(inCard);
            RemoveCardList(inCard);
            RemoveCardList(inCard);
            SortRemoveCard();
            CardListObj[mahjong.CardList.Count].SetActive(false);
            CardListObj[mahjong.CardList.Count + 1].SetActive(false);
            CardListObj[mahjong.CardList.Count + 2].SetActive(false);
            List<int> tempList = new List<int>();
            tempList.Add(inCard);
            tempList.Add(inCard);
            tempList.Add(inCard);
            tempList.Sort();
            GameObject go = LoadModelReturnObj(DownSpecialCard, DownSpecialCardFather);
            //go.transform.localPosition = new Vector3(DownSpecialX, -304, 0);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);
            DownSpecialX = DownSpecialX + 150;
            DownSpecialDic.Add(inCard, go);
        }
        else {
            //吃牌后排序手上的牌
            RemoveCardList(siblingCard1);
            RemoveCardList(siblingCard1);
            SortRemoveCard();
            CardListObj[mahjong.CardList.Count].SetActive(false);
            CardListObj[mahjong.CardList.Count + 1].SetActive(false);

            //显示吃的牌摆到一边
            List<int> tempList = new List<int>();
            tempList.Add(inCard);
            tempList.Add(siblingCard1);
            tempList.Add(siblingCard1);
            tempList.Sort();

            GameObject go = LoadModelReturnObj(DownSpecialCard, DownSpecialCardFather);
            //go.transform.localPosition = new Vector3(DownSpecialX, -304, 0);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);
            DownSpecialX = DownSpecialX + 150;
            DownSpecialDic.Add(inCard, go);

            //移除桌子上面吃碰的牌  inCard user.LastNextSid  returnOtherSeatIndex(LastNextSid)-1     ClearTableCard
            ClearTableCard();
        }       
    }

    //处理他人吃牌
    public void OtherChiCard(int inCard, int siblingCard1, int siblingCard2,int WhoPut) {
        List<int> tempList = new List<int>();
        tempList.Add(inCard);
        tempList.Add(siblingCard1);
        tempList.Add(siblingCard2);
        if (WhoPut == 1)
        {
            //如果是自己不会执行这个判断
        }
        else if (WhoPut == 2)
        {
            //Right
            LoadEffect(PengPath, 2);
            //音效
            PlaySound(38);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
            
            
            //go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
            GameObject go = LoadModelReturnObj(RightSpecialCard, RightSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
        
            RightSpecialY = RightSpecialY - 125;
            RightSpecialDic.Add(inCard, go);
            ClearTableCard();
        }
        else if (WhoPut == 3)
        {
            //Up
            LoadEffect(PengPath, 3);
            //音效
            PlaySound(38);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            //go.transform.localPosition = new Vector3(UpSpecialX, 330, 0);
            GameObject go = LoadModelReturnObj(UpSpecialCard, UpSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(UpSpecialX, 297, 0);
                       
            UpSpecialX = UpSpecialX + 140;
            UpSpecialDic.Add(inCard, go);
            ClearTableCard();
        }
        else if (WhoPut == 4)
        {
            //Left
            LoadEffect(PengPath, 4);
            //音效
            PlaySound(38);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            
            //go.transform.localPosition = new Vector3(LeftSpecialX, -304, 0);
            GameObject go = LoadModelReturnObj(LeftSpecialCard, LeftSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(LeftSpecialX, LeftSpecialY, 0);
            
           
            LeftSpecialY = LeftSpecialY + 130;
            LeftSpecialDic.Add(inCard, go);
            ClearTableCard();
        }
    }
    #endregion

    #region 杠牌处理
    //处理自己杠牌
    public void OwnGangCard(int inCard,MAHJONG_ACTION_TYPE actionType)
    {
        LoadEffect(GangPath, 1);
        //音效
        PlaySound(39);
        //杠牌后排序手上的牌
        RemoveCardList(inCard);
        RemoveCardList(inCard);
        RemoveCardList(inCard);
        SortRemoveCard();
        CardListObj[mahjong.CardList.Count].SetActive(false);
        CardListObj[mahjong.CardList.Count + 1].SetActive(false);
        CardListObj[mahjong.CardList.Count + 2].SetActive(false);

        //显示杠牌摆到一边
        List<int> tempList = new List<int>();
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Sort();
        
       
        GameObject go = LoadModelReturnObj(DownSpecialCard, DownSpecialCardFather);
        go.GetComponent<ShowSpecialCard>().Load(tempList);
        go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);
        
        
        DownSpecialX = DownSpecialX + 200;
        DownSpecialDic.Add(inCard, go);

        if (actionType == MAHJONG_ACTION_TYPE.DarkGang) {

        }
        else if (actionType == MAHJONG_ACTION_TYPE.LightGang) {
            ClearTableCard();
        }
    }

    //处理他人杠牌
    public void OtherGangCard(int inCard,int WhoPut, MAHJONG_ACTION_TYPE actionType)
    {
        List<int> tempList = new List<int>();
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Add(inCard);
        if (WhoPut == 1)
        {
            //如果是自己不会执行这个判断
            //Down
            
        }
        else if (WhoPut == 2)
        {
            //Right
            LoadEffect(GangPath, 2);
            //音效
            PlaySound(39);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
           
            
            //go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
            GameObject go = LoadModelReturnObj(RightSpecialCard,RightSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);    
            
            RightSpecialY = RightSpecialY - 161;
            RightSpecialDic.Add(inCard, go);

            if (actionType == MAHJONG_ACTION_TYPE.DarkGang)
            {

            }
            else if (actionType == MAHJONG_ACTION_TYPE.LightGang)
            {
                ClearTableCard();
            }
        }
        else if (WhoPut == 3)
        {
            //Up
            LoadEffect(GangPath, 3);
            //音效
            PlaySound(39);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            
            
            //go.transform.localPosition = new Vector3(UpSpecialX, 330, 0);
            GameObject go = LoadModelReturnObj(UpSpecialCard,UpSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(UpSpecialX, 297, 0);

            
            
            UpSpecialX = UpSpecialX + 190;
            
            
            UpSpecialDic.Add(inCard, go);

            if (actionType == MAHJONG_ACTION_TYPE.DarkGang)
            {

            }
            else if (actionType == MAHJONG_ACTION_TYPE.LightGang)
            {
                ClearTableCard();
            }
        }
        else if (WhoPut == 4)
        {
            //Left
            LoadEffect(GangPath, 4);
            //音效
            PlaySound(39);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);          
            //go.transform.localPosition = new Vector3(LeftSpecialX, -304, 0);
            GameObject go = LoadModelReturnObj(LeftSpecialCard,LeftSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(LeftSpecialX, LeftSpecialY, 0);
            
            
           
           LeftSpecialY = LeftSpecialY + 160;
            
           
           LeftSpecialDic.Add(inCard, go);

            if (actionType == MAHJONG_ACTION_TYPE.DarkGang)
            {

            }
            else if (actionType == MAHJONG_ACTION_TYPE.LightGang)
            {
                ClearTableCard();
            }
        }
    }
    #endregion 杠牌处理

    #region 加杠
    public void OwnAddGangCard(int inCard)
    {
        LoadEffect(GangPath, 1);
        //音效
        PlaySound(39);
        //杠牌后排序手上的牌
        RemoveCardList(inCard);
        Debug.Log("FourTeenCard"+FourTeenCard+ "CardListObj[13].name"+ CardListObj[13].name+ "inCard"+inCard);

        if (FourTeenCard != inCard) {
            mahjong.CardList.Add(FourTeenCard);
        }
        
        SortRemoveCard();

       

        bool temp = false;

        foreach (KeyValuePair<int, GameObject> kvp in DownSpecialDic)
        {
            if (temp)
            {
                kvp.Value.transform.localPosition = new Vector3(kvp.Value.transform.localPosition.x+50, kvp.Value.transform.localPosition.y, 0);
            }
            if (kvp.Key == inCard) {
                kvp.Value.GetComponent<ShowSpecialCard>().LoadAddGang(inCard);
                temp = true;
            }
            
        }
        DownSpecialX += 50;

        ClearTableCard();
    }

    //处理他人杠牌
    public void OtherAddGangCard(int inCard, int WhoPut)
    {
        List<int> tempList = new List<int>();
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Add(inCard);
        tempList.Add(inCard);
        if (WhoPut == 1)
        {
            //如果是自己不会执行这个判断
            //Down

        }
        else if (WhoPut == 2)
        {
            //Right
            LoadEffect(GangPath, 2);
            //音效
            PlaySound(39);
            
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);

            bool temp = false;
            foreach (KeyValuePair<int, GameObject> kvp in RightSpecialDic)
            {
                if (temp)
                {
                    kvp.Value.transform.localPosition = new Vector3(kvp.Value.transform.localPosition.x, kvp.Value.transform.localPosition.y - 36, 0);
                }
                if (kvp.Key == inCard)
                {
                    kvp.Value.GetComponent<ShowSpecialCard>().LoadAddGang(inCard);
                    temp = true;
                }
                
            }
            

            RightSpecialY = RightSpecialY - 36;

            ClearTableCard();
        }
        else if (WhoPut == 3)
        {
            //Up
            LoadEffect(GangPath, 3);
            //音效
            PlaySound(39);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            bool temp = false;
            foreach (KeyValuePair<int, GameObject> kvp in UpSpecialDic)
            {
                if (temp)
                {
                    kvp.Value.transform.localPosition = new Vector3(kvp.Value.transform.localPosition.x + 60, kvp.Value.transform.localPosition.y, 0);
                }
                if (kvp.Key == inCard)
                {
                    kvp.Value.GetComponent<ShowSpecialCard>().LoadAddGang(inCard);
                    temp = true;
                }
            }
           
            UpSpecialX = UpSpecialX + 60;
            ClearTableCard();

        }
        else if (WhoPut == 4)
        {
            //Left
            LoadEffect(GangPath, 4);
            //音效
            PlaySound(39);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            bool temp = false;
            foreach (KeyValuePair<int, GameObject> kvp in LeftSpecialDic)
            {
                
                if (temp)
                {
                    kvp.Value.transform.localPosition = new Vector3(kvp.Value.transform.localPosition.x, kvp.Value.transform.localPosition.y + 30, 0);
                }
                if (kvp.Key == inCard)
                {
                    kvp.Value.GetComponent<ShowSpecialCard>().LoadAddGang(inCard);
                    temp = true;
                }
                
            }
            LeftSpecialY = LeftSpecialY + 30;

            ClearTableCard();
        }
    }
    #endregion 加杠

    #region 暗杠
    //处理自己杠牌
    public void OwnDarkGangCard(int inCard, MAHJONG_ACTION_TYPE actionType,int LastHandCard)
    {
       

        LoadEffect(GangPath, 1);
        //音效
        PlaySound(39);
        //杠牌后排序手上的牌
        RemoveCardList(inCard);
        RemoveCardList(inCard);
        RemoveCardList(inCard);
        RemoveCardList(inCard);
        if (LastHandCard != 0)
        {
            if (inCard != LastHandCard) {
                mahjong.CardList.Add(LastHandCard);
            }
            CardListObj[13].SetActive(false);
        }
       
        
        SortRemoveCard();
        CardListObj[mahjong.CardList.Count].SetActive(false);
        CardListObj[mahjong.CardList.Count + 1].SetActive(false);
        CardListObj[mahjong.CardList.Count + 2].SetActive(false);
        //CardListObj[user.CardList.Count + 3].SetActive(false);

        //显示杠牌摆到一边
        List<int> tempList = new List<int>();
        tempList.Add(0);
        tempList.Add(0);
        tempList.Add(0);
        tempList.Add(inCard);
        

        GameObject go = LoadModelReturnObj(DownSpecialCardDarkGang, DownSpecialCardFather);
        go.GetComponent<ShowSpecialCard>().Load(tempList);
        go.transform.localPosition = new Vector3(DownSpecialX, -306, 0);


        DownSpecialX = DownSpecialX + 150;
        DownSpecialDic.Add(inCard, go);
    }

    //处理他人杠牌
    public void OtherDarkGangCard(int inCard, int WhoPut, MAHJONG_ACTION_TYPE actionType)
    {
        List<int> tempList = new List<int>();
        tempList.Add(0);
        tempList.Add(0);
        tempList.Add(0);
        tempList.Add(inCard);
        if (WhoPut == 1)
        {
            //如果是自己不会执行这个判断
            //Down

        }
        else if (WhoPut == 2)
        {
            //Right
            LoadEffect(GangPath, 2);
            //音效
            PlaySound(39);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);
            RightBaiCard[RightBaiCard.Count - 1].SetActive(false);
            RightBaiCard.RemoveAt(RightBaiCard.Count - 1);


            //go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);
            GameObject go = LoadModelReturnObj(RightSpecialCardDarkGang, RightSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(RightSpecialX, RightSpecialY, 0);

            RightSpecialY = RightSpecialY - 125;
            RightSpecialDic.Add(inCard, go);

           
        }
        else if (WhoPut == 3)
        {
            //Up
            LoadEffect(GangPath, 3);
            //音效
            PlaySound(39);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);
            UpBaiCard[UpBaiCard.Count - 1].SetActive(false);
            UpBaiCard.RemoveAt(UpBaiCard.Count - 1);


            //go.transform.localPosition = new Vector3(UpSpecialX, 330, 0);
            GameObject go = LoadModelReturnObj(UpSpecialCardDarkGang, UpSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(UpSpecialX, 297, 0);

            UpSpecialX = UpSpecialX + 140;
            UpSpecialDic.Add(inCard, go);

            
        }
        else if (WhoPut == 4)
        {
            //Left
            LoadEffect(GangPath, 4);
            //音效
            PlaySound(39);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            LeftBaiCard[LeftBaiCard.Count - 1].SetActive(false);
            LeftBaiCard.RemoveAt(LeftBaiCard.Count - 1);
            //go.transform.localPosition = new Vector3(LeftSpecialX, -304, 0);
            GameObject go = LoadModelReturnObj(LeftSpecialCardDarkGang, LeftSpecialCardFather);
            go.GetComponent<ShowSpecialCard>().Load(tempList);
            go.transform.localPosition = new Vector3(LeftSpecialX, LeftSpecialY, 0);

            LeftSpecialY = LeftSpecialY + 130;
            LeftSpecialDic.Add(inCard, go);
        }
    }
    #endregion

    #region  胡牌
    public void HuEvent(int WhoPut)
    {
        LoadEffect(HuPath, WhoPut);
        PlaySound(40);
    }
    #endregion

    #region  移除桌子上面吃碰杠的牌
    public void ClearTableCard() {
        Debug.Log("去掉桌子上面的牌");
        int tempLastSeatID = returnOtherSeatIndex(mahjong.LastSeatID);
        Debug.Log("上局seatID："+ mahjong.LastSeatID);
        Debug.Log("隐藏索引：" + tempLastSeatID);
        if (tempLastSeatID==1) {
            //去掉桌子上面的牌
            DownCardShowObj[DownCardCount-1].SetActive(false);
            DownCardCount--;
            
        }
        else if (tempLastSeatID == 2)
        {
            RightCardShowObj[RightCardCount-1].SetActive(false);
            RightCardCount--;
        }
        else if (tempLastSeatID == 3)
        {
            UpCardShowObj[UpCardCount-1].SetActive(false);
            UpCardCount--;
        }
        else if (tempLastSeatID == 4)
        {
            LeftCardShowObj[LeftCardCount-1].SetActive(false);
            LeftCardCount--;
        }
        //隐藏sign
        Sign.SetActive(false);
    }

    #endregion

    #region  iTween
    public void iTweenMove(GameObject moveObj,GameObject targetObj,Transform ClonePosition) {
        GameObject go = Instantiate(moveObj, ClonePosition.position, moveObj.transform.rotation, moveObj.transform.parent) as GameObject;
        moveObj.SetActive(false);
        //iTween.MoveTo(go, targetObj.transform.position, iTweenmoveSpeed);
        Destroy(go);
        moveObj.SetActive(true);
    }
    #endregion iTween

    #region   LoadEffect
    void LoadEffect(string TempPath,int Who) {
        Object obj = Resources.Load(TempPath, typeof(GameObject));
        GameObject go = Instantiate(obj, transform.position, transform.rotation, EffectFather) as GameObject;
        if (Who == 1) {
            go.transform.localPosition =new Vector3(233,-220,0);
        }
        else if (Who == 2) {
            go.transform.localPosition = new Vector3(388, 94, 0);
        }
        else if (Who == 3)
        {
            go.transform.localPosition = new Vector3(-35, 279, 0);
        }
        else if (Who == 4)
        {
            go.transform.localPosition = new Vector3(-433, 88, 0);
        }
        StartCoroutine(DestroyEffect(1.5F,go));
    }
    IEnumerator DestroyEffect(float waitTime,GameObject go)
    {
        yield return new WaitForSeconds(waitTime);
        Destroy(go);
    }

    #endregion

    #region Sound
   void PlaySound(int outCard) {
        //播放 音效 outCard
        if (mahjong.sex == SEX.Female)
        {
            SoundModel.PlaySound(audioClipListMan[outCard]);
        }
        else {
            SoundModel.PlaySound(audioClipListWomen[outCard]);
        }
    }
    #endregion


    GameObject LoadModelReturnObj(string TempPath, Transform fatherTrans)  // fatherTrans 深度统一
    {
        Object obj = Resources.Load(TempPath, typeof(GameObject));
        GameObject go = Instantiate(obj, transform.position, transform.rotation, fatherTrans) as GameObject;
        return go;
    }

    //初始化排序
    void SortCard() {
        BubbleSort(mahjong.CardList);

        
        
        for (int i = 0; i < mahjong.CardList.Count; i++)
        {
            CardListObj[i].SetActive(true);
            CardListObj[i].GetComponent<UISprite>().spriteName = mahjong.CardList[i].ToString();
            CardListObj[i].GetComponent<UIButton>().normalSprite = mahjong.CardList[i].ToString();
            CardListObj[i].name= mahjong.CardList[i].ToString();
        }
    }
    //移除后排序
    void SortRemoveCard() {
        BubbleSort(mahjong.CardList);
        
        for (int i = 0; i < mahjong.CardList.Count; i++)
        {
            CardListObj[i].SetActive(true);
            CardListObj[i].GetComponent<UISprite>().spriteName = mahjong.CardList[i].ToString();
            CardListObj[i].GetComponent<UIButton>().normalSprite = mahjong.CardList[i].ToString();
            CardListObj[i].name = mahjong.CardList[i].ToString();
        }
    }
    //移除user.cardlist有的
    void RemoveCardList(int cardItem) {
        for (int i = 0; i < mahjong.CardList.Count; i++)
        {
            if (mahjong.CardList[i] == cardItem)
            {
                mahjong.CardList.RemoveAt(i);
                break;
            }
        } 
    }
   
    
    
    #region 冒泡排序从大到小
    private void BubbleSort(List<int> R)
    {
        int len = R.Count;
        bool flag = false;
        for (int i = 0; i < len - 1; i++)
        {
            flag = false;
            for (int j = 0; j < len - i - 1; j++)
            {
                if (R[j] < R[j + 1])
                {
                    Swap(R[j], R[j + 1], j, R);
                    flag = true;
                }
            }
            if (!flag)
            {
                break;
            }
        }

    }
    private void Swap(int left, int right, int j, List<int> R)
    {
        int temp = left;
        R[j] = right;
        R[j + 1] = temp;
    }
    #endregion


    //出牌
    public static void SendMahjongPlayRequest(int outCard)
    {
        MahjongPlayRequest MR = new Pb.MahjongPlayRequest { ActionType = EginMahjong.Instance.tempMahjongActionType, InCard = FourTeenCard, OutCard = outCard };
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(MR, MsgId.MahjongPlayRequest);
        EginMahjong.Instance.handCard = 0;
        FourTeenCard = 0;
        EginMahjong.Instance.nextSid = 0;
    }
    //吃的时候出牌



    #region 辅助计算（需放到EginUser中）

    /*-玩家显示-*/
    int DownIndex;//本人玩家在字典索引
    int RightIndex;
    int TopIndex;
    int LeftIndex;
    List<int> tempList = new List<int>();
    void LoadIndex()
    {
        foreach (KeyValuePair<int, int> kvp in mahjong.Otheruid)
        {
            if (mahjong.uid == kvp.Value)
            {
                DownIndex = kvp.Key;
                Debug.Log("本人玩家所在索引" + DownIndex);
                break;
            }
        }
        #region 判断其他玩家生成位置逆时针出牌
        //判断其他玩家生成位置
        if (DownIndex == 1 || DownIndex == 0)  //不加DownIndex==0需要在创建房间成功时候把自己的信息存入EginUser里面的OtherUser信息里面
        {
            RightIndex = 2;
            TopIndex = 3;
            LeftIndex = 4;
        }
        else if (DownIndex == 2)
        {
            RightIndex = 3;
            TopIndex = 4;
            LeftIndex = 1;
        }
        else if (DownIndex == 3)
        {
            RightIndex = 4;
            TopIndex = 1;
            LeftIndex = 2;
        }
        else if (DownIndex == 4)
        {
            RightIndex = 1;
            TopIndex = 2;
            LeftIndex = 3;
        }
        tempList.Add(DownIndex);
        tempList.Add(RightIndex);
        tempList.Add(TopIndex);
        tempList.Add(LeftIndex);
        #endregion 判断其他玩家生成位置逆时针出牌
    }

    private int returnOtherSeatIndex(int seatid)
    {

        int tempReture = mahjong.returnOtherSeatIndex(seatid);

        return tempReture;
    }
    #endregion

    private void OnDestroy()
    {
        FourTeenCard = 0;
    }


}
